<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<title>出入库信息管理</title>
<meta name="decorator" content="default" />
<link href="${ctxStatic}/bootstrap-editable/css/bootstrap-editable.css" rel="stylesheet" />
<link href="${ctxStatic}/bootstrap-table/bootstrap-table.min.css" rel="stylesheet" />
<script src="${ctxStatic}/bootstrap-editable/js/bootstrap-editable.js"></script>
<script src="${ctxStatic}/bootstrap-table/bootstrap-table.js"></script>
<script src="${ctxStatic}/bootstrap-table/locale/bootstrap-table-zh-CN.js"></script>
<script src="${ctxStatic}/bootstrap-table/extensions/editable/bootstrap-table-editable.js"></script>
<script src="${ctxStatic}/common/format/formatOrderData.js"></script>
<script type="text/javascript">
	$(function() {
		$('#tab').bootstrapTable({
			url: "${ctx}/order_detail/bsVaccineOrderDetail/getInDetailById",
	    	toolbar: "#toolbar",
	    	clickToSelect :true,
	    	uniqueId: "id",      //每一行的唯一标识，一般为主键列 
	    	queryParams: function (param) {
	            return {id :'${bsVaccineOrder.id}'};
	        } ,
	    	toolbar: "#toolbar",
	    	clickToSelect :true,
	    	uniqueId: "id",
	        columns: [{
	        	field:"选择",checkbox: true
	        }, {
	            field: 'id',
	            title: 'id',
	            visible: false
	        }, {
	            field: 'productId',
	            title: 'productId',
	            visible: false
	        }, {
	            field: 'batchnoId',
	            title: 'batchnoId',
	            visible: false
	        }, {
	            field: 'name',
	            title: '疫苗名称/注射器类型'
	        }, {
	            field: 'sort',
	            title: '属性',
	            formatter:formatSort
	        }, {
	            field: 'companyName',
	            title: '生产企业'
	        }, {
	            field: 'batchno',
	            title: '批号',
	            formatter:formatBatchno
	        }, {
	            field: 'spec',
	            title: '规格(剂/支或粒)',
	            formatter:formatSpec
	        }, {
	            field: 'dose',
	            title: '剂量'
	        }, {
	            field: 'sellprice',
	            title: '出售价格',
	            width:'150px',
	            editable: {
	                type: 'text',
	                title: '出售价格',
	                defaultValue :'0.0',
	                inputclass:'input-mini',
	                mode:'inline',
	                validate: function (v) {
	    				var sellprice_reg = /^\d+(\.\d+)?$/;
	    				if (!sellprice_reg.test(v)) {
	    					return '价格不合法';
	    				}
	                }
	            }
	        }, {
	            field: 'num',
	            title: '订单数量'
	        }, {
	            field: 'orignprice',
	            title: '成本价格'
	        }, {
	            field: 'vaccExpDate',
	            title: '有效日期',
	            formatter:formatDate
	        }, {
	            field: 'storenum',
	            title: '库存'
	        }, {
	            field: 'storenumF',
	            title: '可用库存',
				formatter : formatStorenumF
	        }]
	    });
		$("#btnPrint").click(function(){
			window.open("${ctx}/order/bsVaccineOrder/print?id=${bsVaccineOrder.id}", "_blank");
		});
		$("#btnConfirmIn").click(function(){//下发入库，状态-->5
			layer.confirm('确认入库？', {icon: 3, title:'提示'}, function(index){
				layer.load(2);
				$("#inputForm").attr("action", "${ctx}/order/bsVaccineOrder/confirmIn?success=true");
				$("#inputForm").submit();
				layer.close(index);
			});
		});
		$("#btnConfirmReturn").click(function(){//退回，状态-->8
			layer.confirm('拒收退回？', {icon: 3, title:'提示'}, function(index){
				layer.load(2);
				$("#inputForm").attr("action", "${ctx}/order/bsVaccineOrder/confirmIn?success=false");
				$("#inputForm").submit();
				layer.close(index);
			});
		});
		$("#inputForm").validate({
			submitHandler : function(form) {
				postOrderDetil(form);
			},
			ignore : ":hidden",
			errorContainer : "#messageBox",
			errorPlacement : function(error, element) {
				$("#messageBox").text("输入有误，请先更正。");
				if (element.is(":checkbox")
						|| element.is(":radio")
						|| element.parent().is(
								".input-append")) {
					error.appendTo(element.parent()
							.parent());
				} else {
					error.insertAfter(element);
				}
			}
		});

	});

	function postOrderDetil(form) {//表单保存时  将此方法中的数据尽行保存
		//校验疫苗运输方式
		debugger;
		var val = $('input:radio[name="transportation"]:checked').val();
		if (!val) {
			$("#t-msg").find("font").text("*必填信息");
			return;
		}
		var val1 = $('input:radio[name="refrigeratetype"]:checked').val();
		if (!val1) {
			$("#r-msg").find("font").text("*必填信息");
			return;
		}
		var rows = $('#tab').bootstrapTable('getData');
		var rowIndex = rows.length;
		var result = false;
		if (rowIndex > 0) {
			$("#tableData").val(JSON.stringify(rows));
			/* layer.confirm('确定保存？', {
				btn : [ '保存', '取消' ] //按钮
			}, function() {
				loading('正在提交，请稍等...');
				form.submit();
			});
			debugger; */
			layer.load(2);
			loading('正在提交，请稍等...');
			form.submit();
		}else{
			layer.confirm('没有添加数据,确定保存？', {
				btn : [ '保存', '取消' ]
			//按钮
			}, function() {
				//debugger;
				layer.load(2);
				loading('正在提交，请稍等...');
				form.submit();
			}, function(index){
				//debugger;
				layer.closeAll('loading'); //关闭加载层  
				layer.close(index);
			});
		}
	}
	//注射器规格字典表
	var specDic = jQuery.parseJSON('${fns:getDictListJson("syringe_spec")}');
</script>
<style type="text/css">
input[type="checkbox"] {
    display: block;
}
</style>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a>疫苗订单信息</a></li>
	</ul>
	<form:form id="inputForm" modelAttribute="bsVaccineOrder"
		action="${ctx}/order/bsVaccineOrder/veiwForm?id=${bsVaccineOrder.id}" method="post"
		class="form-horizontal">
		<form:hidden path="id" />
		<input id="receiveorgcode" type="hidden" name="receiveorgcode" value="${bsVaccineOrder.receiveorgcode}">
		<sys:message content="${message}" />
		<div class="row-fluid">
			<div class="control-group span6 minWidth secondChild">
				<label class="control-label">订单号：</label>
				<div class="controls">
					<form:input path="orderNo" htmlEscape="false" maxlength="50"
						readonly="true" class="span6" />
				</div>
			</div>
			<div class="control-group span6 minWidth">
				<label class="control-label">订单状态：</label>
				<div class="controls">
					<c:choose>  
						<c:when test="${bsVaccineOrder.receiveorgcode==office}"> 
						<form:select path="tempStatus"  readonly="true" disabled="true" class="span6 required ordertype">
							<form:options items="${fns:getDictList('bs_order_status')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
						</form:select>
						</c:when>  
						<c:otherwise> 
						<form:select path="orderStatus"  readonly="true" disabled="true" class="span6 required ordertype">
							<form:options items="${fns:getDictList('bs_order_status')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
						</form:select>
						</c:otherwise>  
					</c:choose>
				</div>
			</div>
		</div>
		<div class="row-fluid">
			<div class="control-group span6">
				<label class="control-label">出库日期：</label>
				<div class="controls">
					<input name="outboundDate" type="text" readonly="readonly"
						disabled maxlength="20" class="span6 Wdate required"
						value="<fmt:formatDate value="${bsVaccineOrder.outboundDate}" pattern="yyyy-MM-dd"/>"
						onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:true});" />
				</div>
			</div>
			<div class="control-group span6 minWidth secondChild">
				<label class="control-label">类型：</label>
				<div class="controls">
					<form:select path="orderType"  readonly="true" disabled="true" class="span6 required ordertype">
						<form:options items="${fns:getDictList('bs_order_ordertype')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
					</form:select>
				</div>
			</div>
		</div>
		<c:if test="${bsVaccineOrder.orderType!=2}">
		<div class="row-fluid">
			<div class="control-group span6 minWidth">
				<label class="control-label">供货单位：</label>
				<div class="controls">
					<form:input path="supplyorgName" htmlEscape="false"
						maxlength="255" readonly="true" class="span6 required" />
				</div>
			</div>
			<div class="control-group span6 minWidth secondChild">
				<label class="control-label">供货单位经手人：</label>
				<div class="controls">
					<form:input path="consignorName" htmlEscape="false" maxlength="50"
						readonly="true" class="span6 required" />
				</div>
			</div>
		</div>
		<div class="row-fluid">
			<div class="control-group span6 minWidth">
				<label class="control-label">收货单位：</label>
				<div class="controls">
					<form:input path="receiveorgName" htmlEscape="false"
						readonly="true" maxlength="255" class="span6 receive required" />
				</div>
			</div>
			<div class="control-group span6 minWidth secondChild">
				<label class="control-label">收货单位经手人：</label>
				<div class="controls">
					<form:input path="consigneeName" htmlEscape="false" maxlength="50"
						readonly="true" class="span6" />
				</div>
			</div>
		</div>
		<div class="row-fluid ">
			<div class="control-group span6 minWidth ">
				<label class="control-label">疫苗运输工具：</label>
				<div class="controls">
					<form:radiobuttons path="transportation" readonly="true"
						disabled="true"
						items="${fns:getDictList('bs_order_transportation')}"
						itemLabel="label" itemValue="value" class="required trantype" />
					<form:input path="otherTransportation" readonly="true"
						htmlEscape="false" maxlength="50" class="input-mini traninput" />
				</div>
			</div>
			<div class="control-group span6 minWidth secondChild">
				<label class="control-label">疫苗冷藏方式：</label>
				<div class="controls">
					<form:radiobuttons path="refrigeratetype" readonly="true"
						disabled="true"
						items="${fns:getDictList('bs_order_refrigeratetype')}"
						itemLabel="label" itemValue="value" class="required reftype" />
					<form:input path="otherRefrigeratetype" readonly="true"
						htmlEscape="false" maxlength="50" class="input-mini refinput" />
				</div>
			</div>
		</div>
		</c:if>
		<div class="row-fluid">
			<div class="control-group span6">
				<label class="control-label">疫苗类型：</label>
				<div class="controls">
					<form:radiobuttons path="cType" readonly="true" disabled="true"
						items="${fns:getDictList('bs_vaccine_type')}"
						itemLabel="label" itemValue="value" class="required reftype" />
				</div>
			</div>
		</div>
		<div class="row-fluid">
		<div class="control-group">
			<label class="control-label">备注信息：</label>
			<div class="controls">
				<form:textarea path="remarks" htmlEscape="false" rows="3"
					readonly="true" style="width: 78%;resize: vertical;"
					maxlength="255" class="input-xlarge" />
			</div>
		</div>
		</div>
		<div class="control-group">
			<input id="tableData" type="hidden" name="tableData">
			<table id="tab" class="table table-bordered table-condensed">
			</table>
		</div>
		<div class="form-actions">
			<button id="btnPrint" class="btn btn-primary" type="button" >打印</button>
			<button id="btnCancel" class="btn btn-primary" type="button" onclick="history.go(-1)">返 回</button>
			<shiro:hasPermission name="order:bsVaccineOrder:confirm">
				<c:if test="${bsVaccineOrder.receiveorgcode==office}">
					<c:if test="${bsVaccineOrder.orderType==1 && bsVaccineOrder.orderStatus==3}">
						<button id="btnConfirmIn" class="btn btn-primary" type="button">入库确认</button>
						<button id="btnConfirmReturn" class="btn btn-primary" type="button">退回</button>
					</c:if>
				</c:if>
			</shiro:hasPermission>
		</div>
	</form:form>
</body>
</html>